package com.wiretap.action.admin.manage;

import java.io.PrintWriter;

import com.wiretap.action.WiretapActionSupport;
import com.wiretap.po.Motion;
import com.wiretap.service.MotionService;
import com.wiretap.util.CommenUtil;
import com.wiretap.util.Constants;
import com.wiretap.util.Pager;

public class MotionManageAction extends WiretapActionSupport {

	private static final long serialVersionUID = -4279615407144132613L;
	private MotionService motionService;
	//消息id
	private String mid;
	//电话号码
	private String phone;
	private Pager<Motion> motions;
	//Motion id
	private String id;
	private int cPage;
	
	@Override
	public String execute() throws Exception {
		cPage = cPage < 1 ? 1 : cPage;
		if (!CommenUtil.isEmpty(phone)) {
			motions = motionService.getAllMotionByPhone(phone, cPage,Constants.DEFAULT_PAGESIEZE);
		}
		return SUCCESS;
	}

	public void deleteMotion() throws Exception{
		response.setContentType(CONTENT_TYPE);
		PrintWriter out = response.getWriter();
		if (motionService.removeMotion(id)){
			out.print("success");
		}else{
			out.print("error");
		}
		out.flush();
		out.close();
	}
	
	public void addMotion() throws Exception {
		response.setContentType(CONTENT_TYPE);
		PrintWriter out = response.getWriter();
		if(motionService.addMotionByMessage(mid)){
			out.print("success");
		}else{
			out.print("error");
		}
		out.flush();
		out.close();
	}
	
	public MotionService getMotionService() {
		return motionService;
	}

	public void setMotionService(MotionService motionService) {
		this.motionService = motionService;
	}

	public String getMid() {
		return mid;
	}

	public void setMid(String mid) {
		this.mid = mid;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public Pager<Motion> getMotions() {
		return motions;
	}

	public void setMotions(Pager<Motion> motions) {
		this.motions = motions;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getcPage() {
		return cPage;
	}

	public void setcPage(int cPage) {
		this.cPage = cPage;
	}
	
}
